

;-  Procedure draws horizontal line - saturated substraction in
;-  every pixel ------------------------------------------------
;-  First stage of triangle rend - sorting coord, calc deltas,
;-  two calling loops --
;-  - see  3stencil.inc file...

;----------------------------------------------------
;-------------in xmm0 - lo -> hi z1, z2 -------------
;--------------- xmm5 - lo -> hi y_min, y_max, x_min,
;- -------------        x_max -----------------------
;--------------- eax - x1 ---------------------------
;--------------- ebx - x2 ---------------------------
;--------------- ecx - y-----------------------------
;--------------- edx - y_res shl 16 + x_res ---------
;--------------- edi - pointer to screen buffer------
;--------------- esi - shadow buffer ----------------

shadow_line:

.xmax   equ [ebp-4]
.xmin   equ [ebp-8]
.ymax   equ [ebp-12]
.ymin   equ [ebp-16]
.xres   equ word[ebp-18]
.yres   equ [ebp-20]
.x1     equ [ebp-24]
.x2     equ [ebp-28]

     push       ebp
     mov        ebp,esp
     sub        esp,30
     movups     .ymin,xmm5
  ;   mov        edx,[xres_vard]
     mov        .yres,edx
     cmp        ecx,.ymin
     jl         .l_quit
     cmp        ecx,.ymax
     jg         .l_quit
   ;  cmp        ecx,.ymax  ;.y_res
   ;  jge        .l_quit

     cmp        eax,ebx
     je         .l_quit
     jl         .l_ok

     xchg       eax,ebx
  .l_ok:
     cmp        eax,.xmax
     jge        .l_quit
     cmp        ebx,.xmin
     jle        .l_quit

     cmp        eax,.xmin
     cmovl      eax,.xmin
     cmp        ebx,.xmax
     cmovg      ebx,.xmax
     mov        .x1,eax
     mov        .x2,ebx

     movzx      edx, .xres
     mov        eax,ecx
     mul        edx                  ; edi = edi + (SIZE_X * y + x1)*4
     add        eax,.x1
     add        esi,eax
     shl        eax,2
     add        edi,eax

     mov        ecx,ebx ;.x2
     sub        ecx,.x1
     mov        eax,0x00444444
     movd       xmm0,eax  ;.col
     
   .ddraw:
     cmp       byte[esi],0
     jne       @f
     movd      xmm1,[edi]
     psubusb   xmm1,xmm0
     movd      [edi],xmm1
     mov       byte[esi],1
    @@:
     add       edi,4
     inc       esi
     loop     .ddraw

   .l_quit:

     mov   esp,ebp
     pop   ebp
ret
